package com.resifind.www.dao.mapper;

import com.resifind.www.po.*;
import com.resifind.www.po.Record;
import com.resifind.www.util.JdbcUtils;

import java.util.List;

/**
 * @author 36069
 */
public class Mappers {

    public static List<User> userMapper(String sql, Object[] params) {
        return JdbcUtils.query(sql, params, rs -> new User(
                rs.getInt("id"),
                rs.getString("phone_num"),
                rs.getString("password_hash"),
                rs.getString("salt")
        ));
    }

    public static List<Client> clientMapper(String sql, Object[] params) {
        return JdbcUtils.query(sql, params, rs -> new Client(
                rs.getInt("id"),
                rs.getInt("user_id"),
                rs.getString("nickname"),
                rs.getInt("age"),
                rs.getString("signature"),
                rs.getString("real_name"),
                rs.getString("ID_num"),
                rs.getDouble("balance"),
                rs.getInt("coin"),
                rs.getString("avatar"),
                rs.getString("status")
        ));
    }

    public static List<Order> orderMapper(String sql, Object[] params) {
        return JdbcUtils.query(sql, params, rs -> new Order(
                rs.getInt("id"),
                rs.getInt("client_id"),
                rs.getInt("room_id"),
                rs.getInt("room_number_id"),
                rs.getInt("merchant_id"),
                rs.getString("trade_status"),
                rs.getString("check_status"),
                rs.getDouble("amount"),
                rs.getString("date"),
                rs.getString("trade_name"),
                rs.getString("keyword"),
                rs.getString("nickname"),
                rs.getString("room_number"),
                rs.getBoolean("client_deleted"),
                rs.getBoolean("merchant_deleted")
        ));
    }

    public static List<Merchant> merchantMapper(String sql, Object[] params) {
        return JdbcUtils.query(sql, params, rs -> new Merchant(
                rs.getInt("id"),
                rs.getInt("user_id"),
                rs.getString("trade_name"),
                rs.getString("address"),
                rs.getString("contact"),
                rs.getString("keyword"),
                rs.getInt("total_sales"),
                rs.getString("business_status"),
                rs.getString("application_status"),
                rs.getDouble("turnover"),
                rs.getString("date"),
                rs.getInt("view"),
                rs.getBoolean("is_favour")
        ));
    }

    public static List<Room> roomMapper(String sql, Object[] params) {
        return JdbcUtils.query(sql, params, rs -> new Room(
                rs.getInt("id"),
                rs.getInt("merchant_id"),
                rs.getString("keyword"),
                rs.getString("bed_type"),
                rs.getString("facility"),
                rs.getString("area"),
                rs.getInt("capacity"),
                rs.getDouble("price"),
                rs.getInt("sales_volume"),
                rs.getInt("surplus")
        ));
    }

    public static List<Recharge> rechargeMapper(String sql, Object[] params) {
        return JdbcUtils.query(sql, params, rs -> new Recharge(
                rs.getInt("id"),
                rs.getInt("client_id"),
                rs.getDouble("amount"),
                rs.getString("date"),
                rs.getString("status")
        ));
    }

    public static List<RoomNumber> roomNumberMapper(String sql, Object[] params) {
        return JdbcUtils.query(sql, params, rs -> new RoomNumber(
                rs.getInt("id"),
                rs.getInt("room_id"),
                rs.getString("room_number"),
                rs.getString("status")
        ));
    }

    public static List<Record> recordMapper(String sql, Object[] params) {
        return JdbcUtils.query(sql, params, rs -> new Record(
                rs.getInt("id"),
                rs.getInt("client_id"),
                rs.getString("date"),
                rs.getInt("bonus_coin")
        ));
    }

    public static List<Browse> browseMapper(String sql, Object[] params) {
        return JdbcUtils.query(sql, params, rs -> new Browse(
                rs.getInt("id"),
                rs.getInt("client_id"),
                rs.getInt("merchant_id"),
                rs.getString("trade_name"),
                rs.getString("time")
        ));
    }

}
